#include "readRasterKeys.hpp"
#include "exceptions.hpp"
#include "magic_enum.hpp"
#include "INIReader_extension.hpp"

namespace hms::raster
{

RasterReader readRasterKeys( const ini::INIReader& settings ){
	using magic_enum::enum_name;
	using Key = RasterReader::Key;

	constexpr auto keySection {"keys"};

	std::array<std::string, RasterReader::nKeys> keys;

	for ( int i {0}; i<RasterReader::nKeys; ++i ){
		keys[i] = settings.Get(
			keySection,
			std::string{ enum_name( static_cast<Key>(i) )},
			""
		);
	}
	RasterReader reader { std::move(keys) };
	ini::read( settings, "storage", "reverse_y", reader.reverseY );

	return reader;
}

RasterReader readRasterKeys( const fs::path& path ){

	// ini::INIReader settings( path.c_str() );
	ini::INIReader settings( path.string() );
	
	if ( settings.ParseError() < 0)
	{
		throw ParseError(
			"Could not find raster settings file "s
			+ path.string()
			+ "!"
		);
	}
	return readRasterKeys(settings);
}

} // namespace hms::raster
